from django.conf.urls.defaults import *

# Uncomment this for admin:
from django.contrib import admin
admin.autodiscover()

from assoce.core.models import Activite
from assoce.materiel.models import Ressource
from assoce.bibli.models import Livre

from assoce.bibli.formtools import ImportForm
from django.conf import settings

import browse
from django.contrib import databrowse

from os.path import dirname, join
_dir = join(dirname(__file__))

activit_list = Activite.objects.all()

urlpatterns = patterns('',
    (r'^.*/home/$', 'django.views.generic.simple.redirect_to', {'url':'/asso/'}),
    (r'^.*/logout/$', 'django.contrib.auth.views.logout'),
    (r'^.*accounts/login/$', 'django.contrib.auth.views.login', {'template_name':'admin/login.html'}),

    (r'media/img/(?P<path>.*)$', 'django.views.static.serve', {'document_root': join(_dir, 'media', 'img'), 'show_indexes': False}),

#    (r'^test/$', CheckStatusFormPreview(CheckStatusForm)),
    (r'^asso/test/$', 'assoce.generic_form.views.generic_form'),

    #(r'^asso/$','django.views.generic.simple.direct_to_template', {'template':'index.html', 'extra_context':{'activite_list':activit_list}}),
    (r'^asso/$', 'django.views.generic.simple.redirect_to', {'url':'/asso/bd/'}),
    #(r'^materiel/$','django.views.generic.simple.direct_to_template', {'template':'materiel.html', 'extra_context':{}}),
    (r'^asso/mmedia/$','django.views.generic.simple.direct_to_template', {'template':'materiel.html', 'extra_context':{'items':Ressource.objects.filter(item__activite__id=2)}}),
    
    (r'^asso/bd/$', 'assoce.bibli.views.index', {'template':'bibli/index.html'}),
    (r'^asso/bd/retour/(?P<id>.*)/$', 'assoce.bibli.views.retour'),
    (r'^asso/bd/list/$', 'assoce.bibli.views.cached_object_list', {'queryset':Livre.objects.all()}),
    (r'^asso/bd/import/$', 'assoce.generic_form.views.generic_form', {'form':ImportForm}),
    (r'^asso/bd/stats/$', 'assoce.bibli.views.stats', {'template':'bibli/stats.html'}),
    
    (r'^asso/mat/(Multimedia)/reserver/(?P<id>.*)/$', 'assoce.materiel.views.reserver', {'template':'materiel/reserver.html'}),
    (r'^asso/mat/Multimedia/list/$', 'django.views.generic.list_detail.object_list', {'queryset':Ressource.objects.filter(item__activite__label='Multimedia')}),
    (r'^asso/mat/(?P<activite_name>.*)/$', 'assoce.materiel.views.index', {'template':'materiel/index.html'}),
    
    ( '^asso/admin/(.*)', admin.site.root),
    ( '^asso/bd/(.*)', admin.site.root),
    (r'^asso/cal/$','django.views.generic.simple.direct_to_template', {'template':'cal.html', 'extra_context':{}}),
    (r'^asso/databrowse/(.*)', databrowse.site.root),

    # Only for development
    (r'^static/(.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)
